package com.mlink.vs.service;

import com.mlink.vs.entity.PiccFence;
import com.mlink.vs.entity.PiccTaskPool;
import com.mlink.vs.entity.PiccUser;
import com.mlink.vs.entity.SignInRequeryResult;

import java.util.ArrayList;
import java.util.List;
import javax.annotation.Generated;

import org.seasar.framework.beans.util.BeanMap;

import static com.mlink.vs.entity.PiccFenceNames.*;
import static org.seasar.extension.jdbc.operation.Operations.*;

/**
 * {@link PiccFence}のサービスクラスです。
 * 
 */
@Generated(value = { "S2JDBC-Gen 2.4.47",
		"org.seasar.extension.jdbc.gen.internal.model.ServiceModelFactoryImpl" }, date = "2017-9-13 14:30:05")
public class PiccFenceService extends AbstractService<PiccFence> {

	/**
	 * 識別子でエンティティを検索します。
	 * 
	 * @param id
	 *            識別子
	 * @return エンティティ
	 */
	public PiccFence findById(String id) {
		return select().id(id).getSingleResult();
	}

	/**
	 * 識別子の昇順ですべてのエンティティを検索します。
	 * 
	 * @return エンティティのリスト
	 */
	public List<PiccFence> findAllOrderById() {
		return select().orderBy(asc(id())).getResultList();
	}

	/**
	 * 根据围栏id 获取围栏信息
	 * 
	 * @return 围栏对象
	 */
	public PiccFence findByFenceId(String fenceId) {
		return jdbcManager.from(PiccFence.class).where("FENCE_ID = ?", fenceId).getSingleResult();
	}

	/**
	 * 获取所有围栏信息
	 * 
	 * @return 围栏对象列表
	 */
	public List<PiccFence> findAllOrderByTime(String fenceType) {
		List<Object> params = new ArrayList<Object>();
		String sql =null;
		if(fenceType != null) {
		 sql = "select * from PICC_FENCE  where  FENCE_TYPE=?";
		params.add(fenceType);
		} else {
			 sql = "select * from PICC_FENCE   ";
		}
		sql = sql + " order by CREATE_TIME desc ";
//		params.add(start);
//		params.add(pageCount);
		return jdbcManager.selectBySql(PiccFence.class, sql, params.toArray()).getResultList();
	}

	/**
	 * 删除指定围栏
	 * 
	 * @return
	 */
	public int delByFenceId(String fenceId) {
		BeanMap params = new BeanMap();

		String sql = "delete  from PICC_FENCE  where  FENCE_GROUP_ID=? ";
		params.put("FENCE_ID", fenceId);
	

		return jdbcManager.updateBySql(sql, String.class).params(fenceId).execute();

	}
	
	/**
	 * 获取指定围栏id
	 * 
	 * @return 围栏对象列表
	 */
	public List<PiccFence> findOneOrderByTime(String fenceGroupId) {
		List<Object> params = new ArrayList<Object>();
		String sql =null;
		sql = "select * from PICC_FENCE  where  FENCE_GROUP_ID=?";
		sql = sql + " order by CREATE_TIME desc ";
		params.add(fenceGroupId);
		return jdbcManager.selectBySql(PiccFence.class, sql, params.toArray()).getResultList();
	}
	//总条数
	public int findTotalCount(String fenceType) {
		List<Object> params = new ArrayList<Object>();
		String sql = "select count(1) from PICC_FENCE nc where   FENCE_TYPE=?";

		params.add(fenceType);
		return jdbcManager.selectBySql(int.class, sql, params.toArray()).getSingleResult();
	}
	
}